﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>终端管理</title>
	<jsp:include page="/resources/inc/head.jsp" flush="true"/>
</head>
<body>
<div class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <!-- Panel Other -->
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <!-- Example Events -->
                         <div class="example-wrap">
                            <div class="example">
                                <div class="btn-group hidden-xs mail-tools tooltip-demo" id="toolbar" role="group">
                                    <shiro:hasPermission name="upms:terminal:create">
                                    <button class="btn btn-white btn-sm" onclick="createAction();" title=""><i  class="glyphicon glyphicon-plus"></i>  新增</button>
                                    </shiro:hasPermission>
                                    <shiro:hasPermission name="upms:terminal:update">
                                    <button class="btn btn-white btn-sm" onclick="updateAction();" title=""><i  class="glyphicon glyphicon-edit"></i>  修改</button>
                                    </shiro:hasPermission>
                                </div>
                                <table id="table" data-height="400" data-mobile-responsive="true"></table>
                            </div>
                        </div>
                        <!-- End Example Events -->
                    </div>
                </div>
            </div>
        </div>
        <!-- End Panel Other -->
    </div>
</div>
<jsp:include page="/resources/inc/footer.jsp" flush="true"/>
<script>
var $table = $('#table');
$(function() {
	// bootstrap table初始化
	$table.bootstrapTable({
		url: '${basePath}/manage/terminal/list',
        method: 'post',
		height: getHeight(),
		striped: true,
		search: true,
        //searchText: '',
		showRefresh: true,
		showColumns: true,
		minimumCountColumns: 2,
		clickToSelect: true,
		detailView: true,
		pagination: true,
		paginationLoop: false,
		sidePagination: 'server',
		silentSort: false,
		smartDisplay: false,
        cache: false,
		escape: true,
		searchOnEnterKey: true,
		idField: 'id',
		maintainSelected: true,
		toolbar: '#toolbar',
		columns: [
		    {field: 'ck', checkbox: true},
			{field: 'id', title: '终端编号'},
			{field: 'name', title: '终端名称'},
            {field: 'version', title: '当前版本'},
			{field: 'url', title: '下载地址'}
		]
	});
})

// 新增
    var createDialog;
    function createAction() {
        createDialog = $.dialog({
            animationSpeed: 300,
            title: '新增终端',
            content: 'url:${basePath}/manage/terminal/create',
            onContentReady: function () {
                initMaterialInput();
                initUploader();
            }
        });
    }
    // 编辑
    var updateDialog;
    function updateAction() {
    var rows = $table.bootstrapTable('getSelections');
    	if (rows.length != 1) {
    		$.confirm({
    			title: false,
    			content: '请选择一条记录！',
    			autoClose: 'cancel|3000',
    			backgroundDismiss: true,
    			buttons: {
    				cancel: {
    					text: '取消',
    					btnClass: 'waves-effect waves-button'
    				}
    			}
    		});
    	} else {
            updateDialog = $.dialog({
                animationSpeed: 300,
                title: '编辑终端',
                content: 'url:${basePath}/manage/terminal/update/' + rows[0].id,
                onContentReady: function () {
                    initMaterialInput();
                    initUploader();
                }
            });
        }
    }
</script>
</body>
</html>